<?php
/*
 * Author:YangBo Created on 2009-1-20:����01:08:28
 * 
 * TODO:TODO
 * as9
 * BaseService
 * 
 */
require_once ('./interfaces/IBaseService.php');
include ("./util/FileSystemUtil.php");
include ("./util/ConfigUtil.php");

class BaseService implements IBaseService {
	protected $_db = null;
	protected $sql;
	protected $result;
	protected $ret; //$result as array;
	

	public function __construct() {
		$this->methodTable = MethodTable::create ( $this );
		
		$sql = null;
		$result = null;
		$ret = array ();
	}
	
	protected function initializeDB() {
		try {
			$this->_db = mysql_connect ( ConfigUtil::SERVER_NAME (), ConfigUtil::MYSQL_USERNAME (), ConfigUtil::MYSQL_PASSWORD () );
			mysql_select_db ( ConfigUtil::MYSQL_TABLENAME (), $this->_db );
			mysql_query ( "SET NAMES 'utf8'" );
		} catch ( Excption $exc ) {
			return $exc;
		}
	}
	
	public function __autoload($class_name) {
		require_once $class_name . '.php';
	}
	
	private function getAuthUser() {
		return Authenticate::getAuthUser ();
	}
	
	public function beforeFilter($methodName) {
	}
	
	private function login($user, $pwd) {
		if (Authenticate::isAuthenticated ())
			return true;
		$isValidUser = true; //test if valid user
		

		if ($isValidUser) {
			Authenticate::login ( $user, "admin" ); //todo:handle roles
			return true;
		}
		return false;
	}
	private function logout() {
		if (Authenticate::isAuthenticated ())
			Authenticate::logout ();
		return true;
	}
	
	public function __destruct() {
	}
}
?>
